package cn.qyd.javathread;

import com.google.common.util.concurrent.Service;

/**
 * @author 邱运铎
 * @date 2024-03-14 15:34
 */
public class ThreadStatusDemo {
    public static synchronized void testMethod() {
        try {
            System.out.println(Thread.currentThread().getName() + " start sleep 2000");
            Thread.sleep(2000);
            System.out.println(Thread.currentThread().getName() + " has sleep 2000");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + " start invoke testMethod");
                testMethod();
                System.out.println(Thread.currentThread().getName() + " has invoked testMethod");
            }
        };
        Thread thread1 = new Thread(runnable);
        Thread thread2 = new Thread(runnable);

        thread1.start();
//        Thread.sleep(1000);
        thread1.join(100);
        thread2.start();

//        while (!Thread.State.TERMINATED.equals(thread1.getState()) &&
//                !Thread.State.TERMINATED.equals(thread2.getState())) {
//            System.out.println(thread1.getName() + " status is :" + thread1.getState());
//            System.out.println(thread2.getName() + " status is :" + thread2.getState());
//        }

        System.out.println(thread1.getName() + " status is :" + thread1.getState());
        System.out.println(thread2.getName() + " status is :" + thread2.getState());
    }
}
